package com.totoro.mapstruct.mapper;

import com.totoro.mapstruct.bean.UserDTO;
import com.totoro.mapstruct.bean.UserModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * Created by Niki on 2018/8/8 9:04
 */
@Mapper(componentModel = "spring")
public interface UserMapper {
    UserMapper instance = Mappers.getMapper(UserMapper.class);

    @Mappings({
            //如果source和target的属性名相同个，可以不用填写
//            @Mapping(source = "nickName", target = "nickName"),
//            @Mapping(source = "userName", target = "userName"),
            //如果属性名相同，又不行获取值，可以用ignore=true参数。注意这里一定要写target，source相同可以不写
            @Mapping(target = "userName", ignore = true),
            @Mapping(source = "age", target = "userAge"),
//            @Mapping(target = "createDate", expression = "java(org.apache.commons.lang3.time.DateFormatUtils.format(userModel.getCreateDate(),\"yyyy-MM-dd HH:mm:ss\"))")
            @Mapping(target = "createDate", dateFormat = "yyyy-MM-dd")
    })
    UserDTO toUserDTO(UserModel userModel);

}
